package com.dl.designmodel.loginAdapter;

import com.dl.pojo.CommonResult;

/**
 * @ProjectName: mcroservices
 * @Package: com.dl.designmodel.loginAdapter
 * @ClassName: PassportForThirdAdapter
 * @Author: 86977
 * @Description: ${description}
 * @Date: 2021/6/29 09:28
 * @Version: 1.0
 */
public class PassportForThirdAdapter extends PassportService implements IPassportForThird {

  @Override
  public CommonResult loginForQQ(String openId) {
    return processLogin(openId,LoginForQQAdapter.class);
  }

  @Override
  public CommonResult loginForWechat(String openId) {
    return processLogin(openId,LoginForWechatAdapter.class);
  }

  @Override
  public CommonResult loginForToken(String token) {
    return processLogin(token,LoginForTokenAdapter.class);
  }

  @Override
  public CommonResult loginForTelphone(String phone, String code) {
    return processLogin(phone,LoginForTelAdapter.class);
  }


  private CommonResult processLogin(String id,Class<? extends ILoginAdapter> clazz){
    try {
      ILoginAdapter adapter = clazz.newInstance();
      if (adapter.support(adapter)){
        return adapter.login(id,adapter);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
}
